package com.example.purchase.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.purchase.R;
import com.example.purchase.bean.BaseBean;
import com.example.purchase.bean.HotBean;

import java.util.List;

public class HotRecyclerViewAdapter extends RecyclerView.Adapter<HotRecyclerViewAdapter.MyViewHolder> {

    private Context context;
    private BaseBean<List<HotBean>> list;

    public HotRecyclerViewAdapter(Context context, BaseBean<List<HotBean>> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View rootView = View.inflate(context, R.layout.recyclerview_hot,null);
        return new MyViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(@NonNull HotRecyclerViewAdapter.MyViewHolder holder, int position) {
        holder.textView.setText(list.getData().get(position).getTitle());
        Glide.with(context).load(list.getData().get(position).getImgUrl()).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return list.getData().size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        public final ImageView imageView;
        public final TextView textView;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.image);
            textView = itemView.findViewById(R.id.title);
        }

    }
}
